﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CarbonMeter
{
    public class LicenseEventArg : EventArgs
    {
        private string _licenseState;
        private string _productName;
        private int _permittedUse;
        private string _eventOwner;

        public string licenseState
        {
            set{ this._licenseState = value; }
            get { return this._licenseState; }
        }

        public string productName
        {
            set { this._productName = value; }
            get { return this._productName; }
        }

        public int permittedUse
        {
            set { this._permittedUse = value; }
            get { return this._permittedUse; }
        }

        public string eventOwner
        {
            set { this._eventOwner = value; }
            get { return this._eventOwner; }
        }

        //constructors
        public LicenseEventArg(string licState, string prodName, int useNum)
        {
            _licenseState = licState;
            _productName = prodName;
            _permittedUse = useNum;
        }
        public LicenseEventArg(string licenseState,string prodName)
        {
            this._licenseState = licenseState;
            _productName = prodName;
            _permittedUse = -1;
        }
        public LicenseEventArg()
        {
            _licenseState = "unknown";
            _productName = "unknown";
            _permittedUse = -1;
        }
    }

    public class LicenseStateEvent
    {
        public LicenseEventArg licenseArg;
        public delegate void LicenseHandler(object sender, LicenseEventArg licenseArg);
        public event LicenseHandler LicenseEvent;

        //cosntructor
        public LicenseStateEvent()
        {
            licenseArg = new LicenseEventArg();
        }

        //publisher: license manager tarafindan cagrilir
        public void OnLicenseEvent(object sender)
        {
            if (LicenseEvent != null)
            {
                LicenseEvent(sender, licenseArg);
            }
        }
    }
}
